package com.chapter04;

import com.bdqn.util.JDBCUtils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Test02_UpdateBlob {
    public static void main(String[] args) throws SQLException, ClassNotFoundException, FileNotFoundException {
        Connection connection = JDBCUtils.getConnection();

        String sql = "UPDATE customers set photo=? WHERE id = ?;";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        FileInputStream fileInputStream = new FileInputStream("file/aa.jpg");
        preparedStatement.setBlob(1, fileInputStream);
        preparedStatement.setInt(2, 1);

        int i = preparedStatement.executeUpdate();
        if (i > 0) {
            System.out.println("成功");
        }
    }
}
